package com.swlz.service.impl;

import java.sql.SQLException;

import com.swlz.dao.WebLinkDAO;
import com.swlz.entity.WebLink;
import com.swlz.exception.CodeException;
import com.swlz.service.WebLinkService;
import com.swlz.vo.PageVO;

/**
 * <pre>
 * 业务逻辑接口具体实现类
 * 网站链接
 * ClassName : com.swlz.service.impl.WebLinkServiceImpl
 * Author : swlz
 * E-Mail : 2233875735@qq.com
 * Date : 2020-06-22 23:07:11
 * Version : 1.0
 * Copyright 2020 swlz.top Inc. All rights reserved. 
 * Warning: this content is only for internal circulation of the company. It is forbidden to divulge it or use it for other commercial purposes
 * </pre>
 **/
public class WebLinkServiceImpl implements WebLinkService {
	
	private WebLinkDAO webLinkDAO = new WebLinkDAO();

	@Override
	public int add(WebLink webLink) throws CodeException {
		try {
			return webLinkDAO.insertSelective(webLink);
		} catch (SQLException e) {
			throw new CodeException(500, "添加网站链接错误",e);
		}
	}

	@Override
	public int update(WebLink webLink) throws CodeException {
		try {
			return webLinkDAO.updateSelective(webLink);
		} catch (SQLException e) {
			throw new CodeException(501, "修改网站链接错误",e);
		}
	}

	@Override
	public int delete(Long linkId) throws CodeException {
		try {
			return webLinkDAO.deleteById(linkId);
		} catch (SQLException e) {
			throw new CodeException(502, "删除网站链接错误",e);
		}
	}

	@Override
	public WebLink get(Long linkId) throws CodeException {
		try {
			return webLinkDAO.selectById(linkId);
		} catch (SQLException e) {
			throw new CodeException(503, "获取网站链接失败",e);
		}
	}

	@Override
	public PageVO<WebLink> page(WebLink webLink, Integer current, Integer rowMax) throws CodeException {
		try {
			long total = webLinkDAO.countByModel(webLink);
			PageVO<WebLink> page = new PageVO<>(total, current, rowMax);
			return page.setList(webLinkDAO.selectByModel(webLink, page.getOffset(), page.getRowMax()));
		} catch (SQLException e) {
			throw new CodeException(504, "获取网站链接分页数据失败",e);
		}
	}


}
